<body>
	<div class="fixed hwrap">
		<a href="javascript:history.back(-1);" target="_parent" class="rel">
			<i class="icon-angle-left"></i>
		</a>
		<a href="javascript:;" target="_parent"></a>
		<h3 class="dyc">收藏夹</h3>
	</div>
	<div style="height:45px;"></div>
	<div class="m_goods">
        <?php if($list):?>
        <ul class="wrap" id="wrap">
            <?php foreach($list as $key => $value):?>
    		<li data-id="">
    		  <div class="trans_head cF">
    			 <span onclick="bindbianji(this)" class="head_r fr">编辑</span>
    		  </div>
    		  <div class="trans_body cF">
    			<a href="/goods/detail?id=<?=$value['goods_id']?>"><img src="<?=$value['pic']?>"></a>
    			<div class="cut_body">
    			  <div class="one" style="display:block">
    				<dl class="dl">
    				  <dt class="myc"><?=$value['title']?></dt>
    				  <dd class="cF"><span class="fl key">￥<?=$value['price']?></span></dd>
    				</dl>
    			  </div>
    			  <div class="opacity two" style="display: none;">
                      <span class="btn" onclick="window.location.href='javascript:delCollect(<?=$value['id']?>);'"><i class="icon-heart"></i>取消收藏</span>
                  </div>
    			</div>
    		  </div>
    		</li>
            <?php endforeach;?>
    	</ul>
		<div id="loading" class="loading hide">正在加载....</div>
       <?php else:?>
           <div class="trans_body cF" style="text-align:center;">还没有记录哦！</div>
      <?php endif;?>
    </div>
<script>

var page = 2;
$(window).scroll(function() {
	timer=null;
	if($(document).scrollTop() >= $(document).height() - $(window).height()){
		 $('#loading').show();
		 window.clearTimeout(timer);
		 $.post("/user/collect",{page:page},function(rs){
			if(rs.code == 0){
				if(rs.data.max_page < page){
					$('#loading').text("亲，没有更多了！").show();
					timer=window.setTimeout('$("#loading").fadeOut()',1200);
				}else{
					var html = "";
					var list = rs.data.list;
					for(var i = 0; i<list.length;i++){
						html += '<li data-id="">';
			    		html +='   <div class="trans_head cF">';
			    		html +=' 	 <span onclick="bindbianji(this)" class="head_r fr">编辑</span>';
			    		html +='   </div>';
			    		html +='   <div class="trans_body cF">';
			    		html +=' 	<a href="/goods/detail?id=' + list[i].goods_id + '"><img src="' + list[i].pic + '"></a>';
			    		html +=' 	<div class="cut_body">';
			    		html +=' 	  <div class="one" style="display:block">';
			    		html +=' 		<dl class="dl">';
			    		html +=' 	  <dt class="myc">' + list[i].title + '</dt>';
			    		html +=' 		  <dd class="cF"><span class="fl key">￥' + list[i].price + '</span></dd>';
			    		html +=' 		</dl>';
			    		html +=' 	  </div>';
			    		html +=' 	  <div class="opacity two" style="display: none;">';
			            html +='           <span class="btn" onclick="window.location.href=\'javascript:delCollect(' + list[i].id + ');\'"><i class="icon-heart"></i>取消收藏</span>';
			            html +='       </div>';
			    		html +=' 	</div>';
			    		html +='   </div>';
			    		html +=' </li>';
					}
					$("#wrap").append(html);
					var i = 0 ;
					var t=window.setInterval(function(){
						i++;
						if(i>5){
							i=0;
							window.clearInterval(t);
						}
					},350);
					$('#loading').hide();
					page++;
				}
			}else{
				layer.msg(rs.msg);
			}
		},"json");
	}
});

//删除收藏
function delCollect(id){
    $.post("/user/delCollect",{id:id},function(data){
        if(data.code==0){
            layer.msg(data.msg);
            window.location.reload();
        }else{
            layer.msg(data.msg);
        }
    },"json");
}
function bindbianji(obj){
	if($(obj).hasClass('panduan')){
		$(obj).removeClass('panduan').text('编辑');
		$(obj).parent().next().find('.two').hide().removeClass('is_animate');;
	}else{
		$(obj).addClass('panduan').text('完成');
		$(obj).parent().next().find('.two').show().addClass('is_animate');;
	}
}
</script>
